﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class newsContent2 : Basic
{
    public string strContent = "";
    public string strNewsRelated = "";
    public int ID = 0;
    public string cpbdList = "";
    public string jdtjList = "";
    public string ydphList = "";
    public string ltjhList = "";
    public string RelStock = "";  //关联股票
    public string strRelStock = "";  //关联股票
    public string _m = "00";  //频道
    public string strChannel = "";
    public string _tid = "0101";  //类别
    public string strClass = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            _tid = OTO.ToStr(Request["cid"], "0101");
            _m = OTO.ToStr(Request["m"], _m);
            ID = OTO.ToInt(Request["ID"], 0);

            Dictionary<string, ChannelEnty> dict = DictChannel();
            strChannel = "<a href=\"" + dict[_m].Url + "\" class=\"w\">" + dict[_m].Name + "</a>";

            string cname = Pub.LoadData(jsonUrl + "news/TypeNameByTypeId.ashx?typeid=" + _tid);
            strClass = "<a href=\"news_" + _m + "_" + _tid + "_1.shtml\" class=\"w\">" + cname + "</a>";

            _title = "益盟操盘手-" + dict[_m].Name + "-" + cname + "";
            _keywords = _title + "-股票,行情,软件,金融,证券,股票论坛,股票软件,证券分析软件,手机炒股,益盟操盘手,操盘手软件,益盟官网";
            _desc = _title + "益盟操盘手:您身边的股票决策师,中国专业股票门户网站,提供权威财经资讯、高速实时行情、免费炒股软件，并为用户提供投资和理财交流论坛";

        }
        catch { }

        strContent = sbContent().ToString();

        strNewsRelated = sbNewsRelated(ID).ToString();

        cpbdList = sbCPBDList().ToString();

        jdtjList = sbJDTJList().ToString();

        ydphList = sbYDPHList().ToString();

        ltjhList = sbLTJHList().ToString();

        BasicHeader(_title, string.Empty, string.Empty, _desc, _keywords);

    }

    private StringBuilder sbContent()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            if (ID > 0)
            {
                StringBuilder sbfx = new StringBuilder();
                sbfx.AppendLine("<div class=\"tj\">");
                sbfx.AppendLine("  <div class=\"tj_l\">");
                sbfx.AppendLine("    <div id=\"ckepop\">			");
                sbfx.AppendLine("	    <a href=\"http://www.jiathis.com/share/?uid=900010\" class=\"jiathis jiathis_txt jtico jtico_jiathis\" target=\"_blank\">分享到：</a>");
                sbfx.AppendLine("	    <a class=\"jiathis_button_qzone\">QQ空间</a>");
                sbfx.AppendLine("	    <a class=\"jiathis_button_tsina\">新浪微博</a>");
                sbfx.AppendLine("            <a class=\"jiathis_button_tqq\">腾讯微博</a>");
                sbfx.AppendLine("           <a class=\"jiathis_button_tsohu\">搜狐微博</a>");
                sbfx.AppendLine("            <a class=\"jiathis_button_t163\">网易微博</a>	");
                sbfx.AppendLine("    </div>  ");
                sbfx.AppendLine("  </div>");
                sbfx.AppendLine("  <div class=\"tj_r\">");
                sbfx.AppendLine("  <iframe src=\"http://open.qzone.qq.com/like?url=http%3A%2F%2Fuser.qzone.qq.com%2F1025234786&type=button_num&width=400&height=30\" allowtransparency=\"true\" scrolling=\"no\" border=\"0\" frameborder=\"0\" style=\"width:400px;height:30px;border:none;overflow:hidden;\"></iframe>");
                sbfx.AppendLine("  </div>");
                sbfx.AppendLine("  <div class=\"clearok\"></div>");
                sbfx.AppendLine("</div>"); 
                
                string url = jsonUrl + "/news/UNews.ashx?id=" + ID;
                string str = Pub.LoadData(url);
                NewsContentEnty obj = JsonConvert.DeserializeObject<NewsContentEnty>(str);
                if (obj != null)
                {
                    sb.AppendLine("<ul class=\"news_14ul\">");
                    sb.AppendLine("<li class=\"h1 center\">" + obj.Title + "</li>");
                    sb.AppendLine("<li class=\"gray sjian center\">" + OTO.ToDate(obj.PTime, DateTime.Now).ToString("yyyy年M月d HH:mm") + " " + obj.Source + "</li>");
                    sb.Append(sbfx.ToString());

                    if (string.IsNullOrEmpty(obj.Summary))
                        sb.AppendLine("<li><div class=\"line\"></div></li>");
                    else
                        sb.AppendFormat("<div class=\"daodu\">[<span class=\"fw\">导读</span>]{0}</div>",obj.Summary);

                    sb.AppendLine("<div class=\"text-indent\">");
                    sb.AppendLine("" + obj.Content + "");
                    sb.AppendLine("</div>");
                    sb.AppendLine("</ul>");
                    sb.AppendLine("<div class=\"clearok\"></div>");

                    if (!string.IsNullOrEmpty(obj.Stcok))
                        strNewsRelated = sbRelatedStock(obj.Stcok).ToString();

                    _title = obj.Title + "-益盟操盘手";
                    _keywords = obj.KeyWord + "-益盟操盘手";
                    _desc = obj.Summary + "-益盟操盘手";
                }
            }
        }
        catch (Exception ex)
        { }
        return sb;
    }

    /// <summary>
    /// 关联股票
    /// </summary>
    /// <param name="codes"></param>
    /// <returns></returns>
    private StringBuilder sbRelatedStock(string codes)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "/news/StockRelateNewsList3.ashx?stocks=" + codes;
            string str = Pub.LoadData(url);
            List<RelatedStock> list = JsonConvert.DeserializeObject<List<RelatedStock>>(str);

            sb.AppendLine("<div class=\"report_bg report_r_1 font-weight\">涉及股票</div>");
            sb.AppendLine("<div class=\"report_r_sjgp\" id=\"sjgp\">");
            sb.AppendLine("<ul class=\"report_xx\">");
            sb.AppendLine("<li class=\"report_r_sjgp_1\">研报</li>");
            sb.AppendLine("<li class=\"report_r_sjgp_3\">股票名称</li>");
            sb.AppendLine("<li class=\"report_r_sjgp_2\">最新价</li>");
            sb.AppendLine("<li class=\"report_r_sjgp_2\">涨跌幅</li>");
            sb.AppendLine("<li class=\"report_r_sjgp_3\">所属行业</li>");
            sb.AppendLine("<li class=\"report_r_sjgp_3\">体检评分</li>");
            sb.AppendLine("<li class=\"report_r_sjgp_4\">千股千评</li>");
            sb.AppendLine("</ul>");
            foreach (var item in list)
            {
                sb.AppendLine("<ul sjgp=\"true\">");
                sb.AppendLine("<li class=\"report_r_sjgp_1\" style=\"text-align:left;\"><img src=\"images/report_ico2.jpg\" /></li>");
                sb.AppendFormat("<li class=\"report_r_sjgp_3\"><a href=\"{2}gg{1}.shtml\">{0}</a></li>", item.StockName, item.Code, quoteUrl);
                sb.AppendFormat("<li class=\"report_r_sjgp_2\">-</li>");
                sb.AppendFormat("<li class=\"report_r_sjgp_2\">-</li>");
                sb.AppendFormat("<li class=\"report_r_sjgp_3\">{2}bk{1}.shtml\">{0}</a></li></li>", item.BkName, item.BkId, quoteUrl);
                sb.AppendFormat("<li class=\"report_r_sjgp_3 red\">{0}分</li>", OTO.ToDecLine(item.TotalScore, 0, "-"));
                sb.AppendFormat("<li class=\"report_r_sjgp_4\">{0}</li>", item.TotalDesc);
                sb.AppendLine("</ul>");
                if (item.Lst.Count > 0)
                {
                    int len = 4;
                    if (item.Lst.Count < len)
                        len = item.Lst.Count;
                    sb.AppendLine("<div class=\"report_r_sjgp_m report_bg hide\" sjgpd=\"true\">");
                    sb.AppendLine("<ul>");
                    for (int i = 0; i < len; i++)
                    {
                        sb.AppendFormat("<li>·<a href=\"newsContent.aspx?id={1}\" class=\"b\">{0}</a></li>", item.Lst[i].Title, item.Lst[i].Id);
                    }
                    sb.AppendLine("</ul>");
                    sb.AppendLine("</div>");
                }
            }
            sb.AppendLine("</div>");
        }
        catch { }
        return sb;
    }

    private StringBuilder sbNewsRelated(int ID)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "/news/NewsRelated.ashx?newsid=" + ID + "&top=5";
            string str = Pub.LoadData(url);
            List<NewsListEnty> list = JsonConvert.DeserializeObject<List<NewsListEnty>>(str);

            sb.Append("<ul class=\"news_14ul news_pos\">");
            sb.Append("<li>相关阅读：</li>");
            for (int i = 0; i < list.Count; i++)
            {
                sb.AppendLine("<li> ·<a href=\"" +GetNewsUrl(_m,_tid,list[i].Id)  + "\" class=\"b\">" + list[i].Title + "</a><span class=\"news_l_rq\">" + OTO.ToDate(list[i].PTime, DateTime.Now).ToString("yyyy-MM-dd") + "</span></li>");
            }
            sb.Append("</ul>");
        }
        catch { }
        return sb;
    }

    private StringBuilder sbCPBDList()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/module.ashx?id=cpbb";
            string str = Pub.LoadData(url);
            List<List<NewsSBEnty>> obj = JsonConvert.DeserializeObject<List<List<NewsSBEnty>>>(str);
            foreach (var item in obj)
            {
                sb.AppendFormat("<li>");
                for (int i = 0; i < item.Count; i++)
                {
                    sb.AppendFormat("<a href=\"{1}\"><span style=\"color:{2};font-weight:{3}\">{0}</span></a> ", item[i].Text, item[i].Url, item[i].Color, item[i].FontWeight);
                }
                sb.AppendFormat("</li>");
                //sb.AppendFormat("<br />");
            }
        }
        catch { }
        return sb;

    }

    private StringBuilder sbJDTJList()
    {
        StringBuilder sbCPBD = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/module.ashx?id=jdtj";
            string str = Pub.LoadData(url);
            List<List<NewsSBEnty>> obj = JsonConvert.DeserializeObject<List<List<NewsSBEnty>>>(str);
            int i = 0;
            foreach (var item in obj)
            {
                //if (item.Count == 3)
                //{
                sbCPBD.Append("<li><a href=\"" + item[0].Url + "\" class=\"b\">" + item[0].Text + "</a>&nbsp;</li>");
                //sbCPBD.Append("<a href=\"" + item[1].Url + "\" class=\"b\">" + item[1].Text + "</a>&nbsp;");
                //sbCPBD.Append("<a href=\"" + item[2].Url + "\" class=\"b\">" + item[2].Text + "</a>&nbsp;");
                i++;
                if (i >= 6)
                    break;
                //}
            }
        }
        catch { }
        return sbCPBD;
    }

    private StringBuilder sbYDPHList()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/ydph.ashx";
            string str = Pub.LoadData(url);
            List<NewsListEnty> list = JsonConvert.DeserializeObject<List<NewsListEnty>>(str);
            int len = 7;
            if (list.Count < len)
                len = list.Count;
            sb.Append("<ul>");
            for (int i = 0; i < len; i++)
            {
                sb.AppendFormat("<li> ·<a href=\"{1}\">{0}</a> </li>", list[i].Title, GetNewsUrl(_m, _tid, list[i].Id));
            }
            sb.Append("</ul>");
        }
        catch { }
        return sb;
    }

    private StringBuilder sbLTJHList()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/ltjh.ashx";
            string str = Pub.LoadData(url);
            List<NewsListEnty> list = JsonConvert.DeserializeObject<List<NewsListEnty>>(str);
            int len = 7;
            if (list.Count < len)
                len = list.Count;
            sb.Append("<ul>");
            for (int i = 0; i < len; i++)
            {
                sb.AppendFormat("<li> ·<a href=\"{1}\">{0}</a> </li>", list[i].Title, list[i].Url);
            }
            sb.Append("</ul>");
        }
        catch
        { }
        return sb;
    }
}